/*     */ package com.zimbra.cs.datasource;
/*     */ 
/*     */ import com.zimbra.cs.account.DataSource;
/*     */ import java.util.Iterator;
/*     */ import java.util.LinkedHashMap;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ import java.util.concurrent.atomic.AtomicInteger;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class SyncErrorManager
/*     */ {
/*     */   private static final int MAX_ENTRIES = 64000;
/*     */   
/*     */   public static enum ItemType
/*     */   {
/*  33 */     ITEM_ID,  REMOTE_ID,  REMOTE_PATH;
/*     */     
/*     */     private ItemType() {} }
/*  36 */   private static final Map<String, AtomicInteger> ERRORS = new LinkedHashMap()
/*     */   {
/*     */     protected boolean removeEldestEntry(Map.Entry e) {
/*  39 */       return size() > 64000;
/*     */     }
/*     */   };
/*     */   
/*     */   private static String key(DataSource ds, ItemType type, Object id) {
/*  44 */     return String.format("%s:%s:%s", new Object[] { ds.getId(), type, id });
/*     */   }
/*     */   
/*     */   public static void clearErrors(DataSource ds) {
/*  48 */     String prefix = ds.getId() + ":";
/*  49 */     synchronized (ERRORS) {
/*  50 */       Iterator<String> it = ERRORS.keySet().iterator();
/*  51 */       while (it.hasNext()) {
/*  52 */         if (((String)it.next()).startsWith(prefix)) {
/*  53 */           it.remove();
/*     */         }
/*     */       }
/*     */     }
/*     */   }
/*     */   
/*     */   public static int incrementErrorCount(DataSource ds, int itemId) {
/*  60 */     return incrementErrorCount(ds, ItemType.ITEM_ID, Integer.valueOf(itemId));
/*     */   }
/*     */   
/*     */   public static int incrementErrorCount(DataSource ds, String remoteId) {
/*  64 */     return incrementErrorCount(ds, ItemType.REMOTE_ID, remoteId);
/*     */   }
/*     */   
/*     */   public static int incrementErrorCount(DataSource ds, ItemType type, Object id) {
/*  68 */     String key = key(ds, type, id);
/*  69 */     synchronized (ERRORS) {
/*  70 */       AtomicInteger count = (AtomicInteger)ERRORS.get(key);
/*  71 */       if (count == null) {
/*  72 */         count = new AtomicInteger();
/*  73 */         ERRORS.put(key, count);
/*     */       }
/*  75 */       return count.incrementAndGet();
/*     */     }
/*     */   }
/*     */   
/*     */   public static void clearError(DataSource ds, int itemId) {
/*  80 */     clearError(ds, ItemType.ITEM_ID, Integer.valueOf(itemId));
/*     */   }
/*     */   
/*     */   public static void clearError(DataSource ds, String remoteId) {
/*  84 */     clearError(ds, ItemType.REMOTE_ID, remoteId);
/*     */   }
/*     */   
/*     */   public static void clearError(DataSource ds, ItemType type, Object id) {
/*  88 */     synchronized (ERRORS) {
/*  89 */       ERRORS.remove(key(ds, type, id));
/*     */     }
/*     */   }
/*     */   
/*     */   public static int getErrorCount(DataSource ds, int itemId) {
/*  94 */     return getErrorCount(ds, ItemType.ITEM_ID, Integer.valueOf(itemId));
/*     */   }
/*     */   
/*     */   public static int getErrorCount(DataSource ds, String remoteId) {
/*  98 */     return getErrorCount(ds, ItemType.REMOTE_ID, remoteId);
/*     */   }
/*     */   
/*     */   public static int getErrorCount(DataSource ds, ItemType type, Object id) {
/* 102 */     synchronized (ERRORS) {
/* 103 */       AtomicInteger count = (AtomicInteger)ERRORS.get(key(ds, type, id));
/* 104 */       return count != null ? count.get() : 0;
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/datasource/SyncErrorManager.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */